#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @author:     spacelacc
# @time:       2025-03-11
# @function:   Main UI of application 'probecoupler'
# @version:    V1

from PySide6.QtWidgets      import QApplication, QMainWindow, QPushButton
from PySide6.QtWidgets      import QHBoxLayout, QVBoxLayout, QSizePolicy
from PySide6.QtWidgets      import QWidget, QStackedWidget


class Constant():
    wtProbeContentSplash = 0
    wtProbeContentMaster = 1
    wtProbeContentConfig = 2

    wtProbePresentVacant = 0
    wtProbePresentDatabase = 1
    wtProbePresentSpreadsheet= 2
    wtProbePresentPickout = 3
    wtProbePresentExecute = 4

    
class ProbeCoupler(QMainWindow):
    def __init__(self, width, height, adapter):
        super().__init__()
        self.setupAttrs(width, height, adapter)
        self.setupIface(adapter)
        self.setupSlots()

    def setupAttrs(self, width, height, adapter):
        wratio = adapter.getfloat('wtProbeCoupler', 'aswratio', fallback=0.8)
        hratio = adapter.getfloat('wtProbeCoupler', 'ashratio', fallback=0.8)
        self.width = wratio*width
        self.height = hratio*height

    def setupIface(self, adapter):
        # left-side vertical button navigator
        self.btGround = QPushButton()
        self.btImport = QPushButton()
        self.btFilter = QPushButton()
        self.btCouple = QPushButton()
        self.btVolume = QPushButton()
        self.btConfig = QPushButton()
        self.btGround.setObjectName(u"btProbePresserGround")
        self.btImport.setObjectName(u"btProbePresserImport")
        self.btFilter.setObjectName(u"btProbePresserFilter")
        self.btCouple.setObjectName(u"btProbePresserCouple")
        self.btVolume.setObjectName(u"btProbePresserVolume")
        self.btConfig.setObjectName(u"btProbePresserConfig")
        btSizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
        self.btGround.setSizePolicy(btSizePolicy)
        self.btImport.setSizePolicy(btSizePolicy)
        self.btFilter.setSizePolicy(btSizePolicy)
        self.btCouple.setSizePolicy(btSizePolicy)
        self.btVolume.setSizePolicy(btSizePolicy)
        self.btConfig.setSizePolicy(btSizePolicy)
        self.wtNavigator = QWidget()
        ctNavigator = QVBoxLayout()
        ctNavigator.setSpacing(0)
        ctNavigator.setContentsMargins(0, 0, 0, 0)
        ctNavigator.addWidget(self.btGround)
        ctNavigator.addWidget(self.btImport)
        ctNavigator.addWidget(self.btFilter)
        ctNavigator.addWidget(self.btCouple)
        ctNavigator.addWidget(self.btVolume)
        ctNavigator.addWidget(self.btConfig)
        self.wtNavigator.setLayout(ctNavigator)

        self.wtVacant = QWidget()
        self.wtVacant.setObjectName(u"wtProbePresentVacant")

        # Probe Present Execute: wtProbePresentExecute
        self.wtRenderer = QWidget()
        self.wtPlotter = QWidget()
        self.btPrev = QPushButton()
        self.btNext = QPushButton()
        self.btPrev.setObjectName(u"btProbePresserPrev")
        self.btNext.setObjectName(u"btProbePresserNext")
        ctGroup = QHBoxLayout()
        ctGroup.addWidget(self.btPrev)
        ctGroup.addWidget(self.btNext)
        wtGroup = QWidget()
        wtGroup.setLayout(ctGroup)
        ctPlotter = QVBoxLayout()
        ctPlotter.addWidget(self.wtRenderer)
        ctPlotter.addWidget(wtGroup)
        ctPlotter.setStretch(0, 5)
        ctPlotter.setStretch(1, 1)
        self.wtPlotter.setLayout(ctPlotter)
        self.wtPrinter = QWidget()
        self.wtPrinter.setObjectName(u"wtProbePrinter")
        ctExecute = QHBoxLayout()
        ctExecute.setSpacing(0)
        ctExecute.setContentsMargins(0, 0, 0, 0)
        ctExecute.addWidget(self.wtPlotter)
        ctExecute.addWidget(self.wtPrinter)
        ctExecute.setStretch(0, 3)
        ctExecute.setStretch(1, 1)
        self.wtExecute = QWidget()
        self.wtExecute.setObjectName(u"wtProbePresentExecute")
        self.wtExecute.setLayout(ctExecute)

        # Probe Present Database 
        self.wtDatabase = QWidget()
        self.wtDatabase.setObjectName(u"wtProbePresentDatabase")

        # Probe Present Spreadsheet
        self.wtSpreadsheet = QWidget()
        self.wtSpreadsheet.setObjectName(u"wtProbePresentSpreadsheet")

        # Probe Present Pickout
        self.wtPickout = QWidget()
        self.wtPickout.setObjectName(u"wtProbePresentPickout")
        # The center-core stacked widget
        self.wtStackFlex = QStackedWidget()
        self.wtStackFlex.addWidget(self.wtVacant)
        self.wtStackFlex.addWidget(self.wtDatabase)
        self.wtStackFlex.addWidget(self.wtSpreadsheet)
        self.wtStackFlex.addWidget(self.wtPickout)
        self.wtStackFlex.addWidget(self.wtExecute)

        # ProbeParader: The center-left parader widget
        self.wtParader = QWidget()
        self.wtParader.setObjectName(u"wtProbeParader")

        ##########  The core-region widget  ############
        ctMaster = QHBoxLayout()
        ctMaster.setSpacing(0)
        ctMaster.setContentsMargins(0, 0, 0, 0)
        ctMaster.addWidget(self.wtParader)
        ctMaster.addWidget(self.wtStackFlex)
        ctMaster.setStretch(0, 1)
        ctMaster.setStretch(1, 4)
        # Master flexible widget for multiple usage
        self.wtMaster = QWidget() 
        self.wtMaster.setObjectName(u"wtProbeContentMaster")
        self.wtMaster.setLayout(ctMaster)
        # Splash logo widget
        self.wtSplash = QWidget() 
        self.wtSplash.setObjectName(u"wtProbeContentSplash")
        # Setting config widget
        self.wtConfig = QWidget() 
        self.wtConfig.setObjectName(u"wtProbeContentConfig")

        ######### The Central-Widget of 'QMainWindow' #########
        # The container of most valuable three right widgets.
        self.wtStackBase = QStackedWidget()
        self.wtStackBase.addWidget(self.wtSplash)    # index: 0
        self.wtStackBase.addWidget(self.wtMaster)    # index: 1
        self.wtStackBase.addWidget(self.wtConfig)    # index: 2
        # The container of application
        ctCentral = QHBoxLayout()
        ctCentral.setSpacing(0)
        ctCentral.setContentsMargins(0, 0, 0, 0)
        ctCentral.addWidget(self.wtNavigator)
        ctCentral.addWidget(self.wtStackBase)
        self.wtCentral = QWidget(self)
        self.wtCentral.setObjectName(u'wtProbeCouplerCentral')
        self.wtCentral.setLayout(ctCentral)
        self.setCentralWidget(self.wtCentral)
        self.resize(self.width, self.height)

    def setupSlots(self):
        self.btGround.clicked.connect(self.btGroundClickedHandler)
        self.btImport.clicked.connect(self.btImportClickedHandler)
        self.btFilter.clicked.connect(self.btFilterClickedHandler)
        self.btCouple.clicked.connect(self.btCoupleClickedHandler)
        self.btVolume.clicked.connect(self.btVolumeClickedHandler)
        self.btConfig.clicked.connect(self.btConfigClickedHandler)

    def btGroundClickedHandler(self):
        if self.wtStackBase.currentIndex() != Constant.wtProbeContentSplash:
            self.wtStackBase.setCurrentIndex(Constant.wtProbeContentSplash)

    def btImportClickedHandler(self):
        if self.wtStackBase.currentIndex() != Constant.wtProbeContentMaster:
            self.wtStackBase.setCurrentIndex(Constant.wtProbeContentMaster)
        if self.wtStackFlex.currentIndex() != Constant.wtProbePresentVacant:
            self.wtStackFlex.setCurrentIndex(Constant.wtProbePresentVacant)

    def btFilterClickedHandler(self):
        if self.wtStackBase.currentIndex() != Constant.wtProbeContentMaster:
            self.wtStackBase.setCurrentIndex(Constant.wtProbeContentMaster)
        if self.wtStackFlex.currentIndex() != Constant.wtProbePresentPickout:
            self.wtStackFlex.setCurrentIndex(Constant.wtProbePresentPickout)

    def btCoupleClickedHandler(self):
        if self.wtStackBase.currentIndex() != Constant.wtProbeContentMaster:
            self.wtStackBase.setCurrentIndex(Constant.wtProbeContentMaster)
        if self.wtStackFlex.currentIndex() != Constant.wtProbePresentExecute:
            self.wtStackFlex.setCurrentIndex(Constant.wtProbePresentExecute)

    def btVolumeClickedHandler(self):
        if self.wtStackBase.currentIndex() != Constant.wtProbeContentMaster:
            self.wtStackBase.setCurrentIndex(Constant.wtProbeContentMaster)
        if self.wtStackFlex.currentIndex() != Constant.wtProbePresentDatabase:
            self.wtStackFlex.setCurrentIndex(Constant.wtProbePresentDatabase)

    def btConfigClickedHandler(self):
        if self.wtStackBase.currentIndex() != Constant.wtProbeContentConfig:
            self.wtStackBase.setCurrentIndex(Constant.wtProbeContentConfig)



#app = QApplication()
#win = ProbeCoupler(699, 299, 10)
#win.show()
#app.exec()
